-- Grave
-- Created by chengb Aug/4/2016
-- 坟墓

-- 初始化
function initGrave(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 建筑奖励已被领取
            if BraveVSDragonM.hasGotBuildingBonus(self.gridData.class) then
                self:openBuildingView();
                return;
            end

            local function okFunc()
                local function callback()
                    -- 执行奖励
                    DungeonActionM.go("brave_building_bonus", self.gridData:getPos());
                end

                -- 锁屏
                wait(2.5);

                -- 播放祭坛激活的光效
                playOddAltarActiveEffect(self, callback);
            end

            self:openBuildingView(okFunc);
        end
    end

    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.icon:setVisible(true);
end
